/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classes;

import java.sql.ResultSet;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import pojo.Customer;

/**
 *
 * @author Eman
 */
public class CustomerWrapper {

    private Customer customer;

    public CustomerWrapper() {
    }

    public CustomerWrapper(Customer customer) {
        this.customer = customer;
    }

    public CustomerWrapper(int id, String firstName, String lastName, String email,
            String password, String type, Date birthDate, float credit) {
        this.customer.setId(id);
        this.customer.setFirstName(firstName);
        this.customer.setLastName(lastName);
        this.customer.setEmail(email);
        this.customer.setPassword(password);
        this.customer.setType(type);
        this.customer.setBirthDate(birthDate);
        this.customer.setCredit(credit);
    }

    public Customer Login(String name, String passw) {

        SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        Criteria logincr = session.createCriteria(pojo.Customer.class).add(Restrictions.eq("firstName", name)).add(Restrictions.eq("password", passw));  
        return (pojo.Customer) logincr.uniqueResult();
    }
}
